<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<script type="text/javascript" src="${ctx}/js/jquery.printarea.js"></script>
<table class="display" id="example">
	<thead>
		<tr>
			<th>选择</th>
			<th>姓名</th>
			<th>面试岗位</th>
			<th>报到单位</th>
			<th>面试时间</th>
			<th>到岗时间</th>
			<th>状态</th>
			<th>识别证制作</th>
		</tr>
	</thead>
	<tbody>
		<s:if
			test="#request.identityCardPojos==null || #request.identityCardPojos.size() <= 0">
			<tr class="gradeA">
				<td colspan="8">暂无员工报到数据</td>
			</tr>
		</s:if>
		<s:else>
			<s:iterator value="#request.identityCardPojos" var="icard"
				status="sta">
				<s:if test="#sta.even">
					<tr class="gradeA">
				</s:if>
				<s:else>
					<tr class="gradeC">
				</s:else>

				<td><input type="checkbox" name="chk_resume"
					value="${icard.id}" /></td>
				<td>${icard.name}</td>
				<td>${icard.dutyName}</td>
				<td>${icard.organization.path}</td>
				<td><s:if test="#interview.interviewTime == null">未开始</s:if> <s:else>
						<fmt:formatDate value="${icard.interviewTime}"
							pattern="yyyy-MM-dd"></fmt:formatDate>
					</s:else></td>
				<td><s:if test="#interview.interviewTime == null">未报到</s:if> <s:else>
						<fmt:formatDate value="${icard.reportTime}" pattern="yyyy-MM-dd"></fmt:formatDate>
					</s:else></td>
				<td><s:if
						test="#icard.receiveState == null || #icard.receiveState == false">
						<a href="javascript:void(0)" value="Simple Popover"
							id="simple-button${icard.arrangeId}" class="button"><span
							class="icon" style="background:url(${ctx}/images/img/delete.png)">&nbsp;</span>未领取</a>

						<div id="simple-popover${icard.arrangeId}" class="popover">
							<header> 识别证领取状态</header>
							<section>
								<div class="content">
									<nav>
										<ul>
											<li class="read"><a><span class="avatar"></span> <input
													type="radio" name="rd_${arrangeId}" value="1" /> 已领取 </a><a>
													<button class="button" type="button"
														onclick="changeStaffCardState(${icard.arrangeId})">
														<span class="icon"
															style="background:url(${ctx}/images/img/printer.png)">&nbsp;</span>确定
													</button>
											</a><a> </a></li>
										</ul>
									</nav>
								</div>
							</section>
						</div>
						<script>
                        $(document).ready(function () {
                            $('#simple-button${icard.arrangeId}').popover('#simple-popover${icard.arrangeId}', {});
                            $('#top-button').popover('#top-popover', {preventLeft:true, preventRight:true, preventBottom:true});
                        });
                    </script>
					</s:if> <s:else>
						<a href="javascript:void(0)" value="Simple Popover"
							id="simple-button4" class="button"><span class="icon"
							style="background:url(${ctx}/images/img/accept.png)">&nbsp;</span>已领取</a>
					</s:else></td>
				<td><a class="button" id="icard_${icard.employeeId}"
					value="Simple Popover" href="#"
					onclick="generateCardInfo(${icard.arrangeId},${icard.employeeId})"><span
						style="background:url(${ctx}/images/img/page_add.png)"
						class="icon">&nbsp;</span><span
						id="icard_desc_${icard.employeeId}"> <s:if
								test="#icard.dentificationCardTime == null">生成</s:if> <s:else>重新生成</s:else></span></a>

					<div id="icard_layout_${icard.employeeId}" class="popover"
						style="width: 505px">
						<header> 识别证</header>
						<section>
							<div class="content" >
                                <div id="icard_printarea_${icard.employeeId}">
                                    <table  width="502" border="0" cellspacing="0" cellpadding="0"
                                        style="background-image:url(${ctx}/images/SBZ_B.jpg);">
                                        <tr>
                                            <td width="23">&nbsp;</td>
                                            <td width="170" height="110">&nbsp;</td>
                                            <td width="122">&nbsp;</td>
                                            <td width="163" align="center">&nbsp;</td>
                                            <td width="27">&nbsp;</td>
                                        </tr>
                                        <tr>
                                            <td height="30">&nbsp;</td>
                                            <td rowspan="5" width="162" height="189"><img
                                                id="avatar_${icard.employeeId}" src="" width="162"
                                                height="189" /></td>
                                            <td>&nbsp;</td>
                                            <td align="center"><font style="font-size: 16px"
                                                id="workno_${icard.employeeId}"></font></td>
                                            <td>&nbsp;</td>
                                        </tr>
                                        <tr>
                                            <td height="30">&nbsp;</td>
                                            <td>&nbsp;</td>
                                            <td align="center"><font style="font-size: 16px"
                                                name="empolyeeName">${icard.name}</font></td>
                                            <td>&nbsp;</td>
                                        </tr>
                                        <tr>
                                            <td height="30">&nbsp;</td>
                                            <td>&nbsp;</td>
                                            <td align="center"><font style="font-size: 16px"
                                                id="second_org_${icard.employeeId}">${icard.organization.path}</font>
                                            </td>
                                            <td>&nbsp;</td>
                                        </tr>
                                        <tr>
                                            <td height="30">&nbsp;</td>
                                            <td>&nbsp;</td>
                                            <td align="center"><font style="font-size: 16px"
                                                id="third_org_${icard.employeeId}"></font></td>
                                            <td>&nbsp;</td>
                                        </tr>
                                        <tr>
                                            <td height="30">&nbsp;</td>
                                            <td>&nbsp;</td>
                                            <td align="center"><font style="font-size: 16px">${icard.dutyName}</font></td>
                                            <td>&nbsp;</td>
                                        </tr>
                                        <tr>
                                            <td>&nbsp;</td>
                                            <td>&nbsp;</td>
                                            <td>&nbsp;</td>
                                            <td align="center">&nbsp;</td>
                                            <td>&nbsp;</td>
                                        </tr>
                                    </table>
                                </div>
								<nav>
									<ul>
										<li class="new"><a><span class="avatar"></span>
												<button class="button" type="button"
													onclick="printIcardInfo(${icard.employeeId})">
													<span class="icon"
														style="background:url(${ctx}/images/img/printer.png)">&nbsp;</span>打印识别证
												</button> </a></li>
									</ul>
								</nav>
							</div>
						</section>
					</div> <script>
                        $(document).ready(function () {
                            $('#icard_${icard.employeeId}').popover('#icard_layout_${icard.employeeId}', {});
                            //$('#top-button').popover('#top-popover', {preventLeft: true, preventRight: true, preventBottom:true});
                        });
                    </script></td>
				</tr>
			</s:iterator>
		</s:else>
	</tbody>
</table>

<p>
	<%@ include file="/WEB-INF/pages/common/main_orgtab_pager.jsp"%>
</p>

<script type="text/javascript">

	/**
	 * 修改识别卡信息
	 */
    function changeStaffCardState(interviewArrangeId) {
        var state = $("input:radio[name='rd_" + interviewArrangeId + "']:checked").val();
        if (state == undefined) {
            alert("请选择状态!");
            return;
        }

        var url = "${ctx}/invite/post_stafficard.xhtml";
        $.ajax(url, {
            type:"POST",
            data:{"op":"st", "rec_state":state, "interviewArrangeId":interviewArrangeId},
            dataType:"json",
            cache:false,
            success:function (a) {
                alert("操作成功！");
                loadListContent("${ctx}/invite/staff_card.xhtml", currentSelOrgId);
                $("#simple-popover" + interviewArrangeId).remove();
            },
            error:function (XMLHttpRequest, textStatus, errorThrown) {
                alert('提交发生异常');
            },
            complete:function () {
            }
        });
    }
	
	/**
	 * 修改Card产生时间
	 */
    function changeCardGenerateTime(interviewArrangeId,eId) {
        var url = "${ctx}/ajax/generate_cardtime.xhtml";
        $.ajax(url, {
            type:"POST",
            data:{"employeeId":eId,"interviewArrangeId":interviewArrangeId},
            dataType:"json",
            cache:false,
            success:function (a) {
				//
            },
            error:function (XMLHttpRequest, textStatus, errorThrown) {
                //alert('提交发生异常');
            },
            complete:function () {
            }
        });
    }

    /**
     * 产生识别证信息
     * @param eId
     */
    function generateCardInfo(interviewArrangeId,eId) {
        if (eId <= 0) {
            return;
        }

        var orgPath = $("#second_org_" + eId).html();
        if (orgPath.split("/").length > 3) {
            $("#third_org_" + eId).html(orgPath.split("/")[2] + "/" + orgPath.split("/")[3]);
            $("#second_org_" + eId).html(orgPath.split("/")[1]);
        }else if (orgPath.split("/").length > 2) {
            $("#third_org_" + eId).html(orgPath.split("/")[2]);
            $("#second_org_" + eId).html(orgPath.split("/")[1]);
        } else if (orgPath.split("/").length > 1) {
            $("#third_org_" + eId).html("");
            $("#second_org_" + eId).html(orgPath.split("/")[1]);
        } else {
            $("#third_org_" + eId).html("");
            $("#second_org_" + eId).html(orgPath.split("/")[0]);
        }

        var url = "${ctx}/ajax/query_workinfo.xhtml";
        $.ajax(url, {
            type:"get",
            data:{"id":eId},
            dataType:"json",
            cache:false,
            success:function (data) {
                if (data.workno != null) {
                    $("#workno_" + eId).html(data.workno);
                }
                if (data.avatar != null && data.avatar != "") {
                    $("#avatar_" + eId).attr("src", data.avatar + "?t=" + parseInt(new Date().valueOf() / 1000));
                }
                changeCardGenerateTime(interviewArrangeId,eId);
                $("#icard_desc_" + eId).html("重新生成");
            },
            error:function (XMLHttpRequest, textStatus, errorThrown) {
                alert('查询数据发生异常');
            },
            complete:function () {
            }
        });
    }

    function printIcardInfo(eId) {
        $("#icard_printarea_" + eId).printArea();
    }
</script>